package com.haocjia.esdemo.elastic.service;

import org.elasticsearch.action.delete.DeleteResponse;
import org.elasticsearch.action.get.GetResponse;
import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.action.update.UpdateResponse;
import org.elasticsearch.client.indices.CreateIndexResponse;

import java.io.IOException;
import java.util.List;
import java.util.Map;

public interface ElasticSearchService {

    /**
     * 分页搜索 es
     *
     * @param val
     * @param pageNum
     * @param pageSize
     * @param sort
     * @param index
     * @return
     */
    List<Map<String, Object>> search(String[] fields, String val, Integer pageNum,
                                     Integer pageSize, String sort, String... index) throws IOException;


    GetResponse get(String index, Long id) throws IOException;

    /**
     * 新增一个doc
     *
     * @param index
     * @param jsonString
     * @param id
     * @return
     * @throws IOException
     */
    IndexResponse add(String index, String jsonString, Long id) throws IOException;

    /**
     * 更新doc
     *
     * @param string
     * @param jsonString
     * @param id
     * @return
     * @throws IOException
     */
    UpdateResponse update(String string, String jsonString, Long id) throws IOException;

    /**
     * 判断文档是否存在
     *
     * @param index
     * @param id
     * @return
     */
    Boolean exists(String index, Long id) throws IOException;

    /**
     * 删除一个doc
     *
     * @param index
     * @param id
     * @return
     */
    DeleteResponse deleteById(String index, Long id) throws IOException;

    /**
     * 创建一个索引
     *
     * @param index
     * @param mapping
     * @param shards
     * @param replicas
     * @return
     * @throws IOException
     */
    CreateIndexResponse createIndex(String index, String mapping, Integer shards, Integer replicas) throws IOException;

    /**
     * 判断索引是否存在
     *
     * @param index
     * @return
     * @throws IOException
     */
    Boolean exists(String index) throws IOException;

    /**
     * 删除索引
     *
     * @param index
     * @return
     * @throws IOException
     */
    AcknowledgedResponse deleteIndex(String index) throws IOException;
}
